package org.java2me.mobileboxing;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: aterreno
 * Derived from DateHelper from the kommons project.
 */
public class DateHelper {
    public static String printTime(long millis) {
        String ret;
        String min = "-";
        String sec = "-";

        if (millis > 0) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date(millis));

            min = String.valueOf(cal.get(Calendar.MINUTE));
            sec = String.valueOf(cal.get(Calendar.SECOND));

            min = addInitialZero(min);
            sec = addInitialZero(sec);
        }

        ret =  min + ":" + sec;        

        return ret;
    }

    private static String addInitialZero(String s) {
        if (s.length() == 1) {
            s = ("0" + s);
        }

        return s;
    }
}
